package com.wanmait.zaisousuo.webcontroller;


import com.wanmait.zaisousuo.exception.ArticleNotFoundException;
import com.wanmait.zaisousuo.exception.QuestionNotFoundException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class AdviceController {

    //文章无法找到
    @ExceptionHandler({ArticleNotFoundException.class})
    public ModelAndView ArticleException(ArticleNotFoundException e){
         ModelAndView mv = new ModelAndView();
         mv.addObject("message",e.getMessage());
         mv.setViewName("/error/NotFoundException");
         return mv;
    }

    //问答无法找到
    @ExceptionHandler({QuestionNotFoundException.class})
    public ModelAndView QuestionException(QuestionNotFoundException e){
        ModelAndView mv = new ModelAndView();
        mv.addObject("message",e.getMessage());
        mv.setViewName("/error/NotFoundException");
        return mv;
    }




}
